package cz.hanis.android.geography.adapters;

import cz.hanis.android.geography.R;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ContinentSpinnerAdapter extends ArrayAdapter<String> {

	private LayoutInflater inflater;
	
	private String[] names;
	private int icons[];

	public ContinentSpinnerAdapter(Context context, int textViewResourceId, String[] names, int[] icons) {
		super(context, textViewResourceId, names);
		this.icons = icons;
		this.names = names;
		inflater = ((Activity) context).getLayoutInflater();		
	}

	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		return getCustomView(position, convertView, parent);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		return getCustomView(position, convertView, parent);
	}

	public View getCustomView(int position, View convertView, ViewGroup parent) {

		View row = inflater.inflate(R.layout.continent_row, parent, false);
		TextView label = (TextView) row.findViewById(R.id.cr_name);
		label.setText(names[position]);

		ImageView icon = (ImageView) row.findViewById(R.id.cr_image);
		icon.setImageResource(icons[position]);

		return row;
	}
}
